package com.ljy.my_study.leetcode.颜色分类;

import java.util.Arrays;

/**
 * @author lijunying
 * @date 2021/9/18 11:20
 */
public class TestMain {

    public static void main(String[] args) {
        int[] nums={2,0,2,1,1,0};
        new TestMain().sortColors(nums);
        System.out.println(Arrays.toString(nums));
    }

    public void sortColors(int[] nums) {
        int[] array=new int[3];
        int len=nums.length;
        for(int i=0;i<len;i++){
            int index=nums[i];
            int count=array[index];
            count++;
            array[index]=count;
        }
        int index=0;
        for(int i=0;i<len;i++){
            while(index<3&&array[index]<=0){
                index++;
            }
            if(index>=3){
                break;
            }
            nums[i]=index;
            array[index]--;
        }
    }
}
